/*
 *
 * Copyright (C) 2012 Walter Lütgenau
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package offset.nodes.server.config;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import offset.nodes.maven.Registration;
import offset.nodes.server.controller.contentType.ContentTypeMapper;
import offset.nodes.server.jsfbean.ToolbarRenderer;
import offset.nodes.server.model.RepositoryStartupExtension;
import offset.nodes.server.servlet.ServiceContainer;
import offset.nodes.server.view.component.applet.AppletJarConfigElement;
import org.springframework.beans.factory.InitializingBean;

/**
 *
 * @author
 * Walter
 * L�tgenau
 */
public class ModuleConfig implements InitializingBean {

    NodesConfig nodesConfig;
    Collection<ServiceContainer> services;
    Collection<RepositoryStartupExtension> startupExtensions;
    Collection<ContentTypeMapper> contentTypeMappers;
    HashMap<String,HashMap<String,String>> navigations;
    Collection<AppletJarConfigElement> appletJars;
    String clientConfigFile;
    List<ToolbarRenderer> toolbars;
    List<Registration> rmiServices;

    public void setNodesConfig(NodesConfig nodesConfig) {
        this.nodesConfig = nodesConfig;
    }

    public void setServices(Collection<ServiceContainer> services) {
        this.services = services;
    }

    public void setStartupExtensions(Collection<RepositoryStartupExtension> startupExtensions) {
        this.startupExtensions = startupExtensions;
    }

    public void setContentTypeMappers(Collection<ContentTypeMapper> contentTypeMappers) {
        this.contentTypeMappers = contentTypeMappers;
    }

    public void setNavigations(HashMap<String,HashMap<String,String>> navigations) {
        this.navigations = navigations;
    }

    public void setAppletJars(Collection<AppletJarConfigElement> appletJars) {
        this.appletJars = appletJars;
    }

    public void setClientConfigFile(String clientConfigFile) {
        this.clientConfigFile = clientConfigFile;
    }

    public List<ToolbarRenderer> getToolbars() {
        return toolbars;
    }

    public void setToolbars(List<ToolbarRenderer> toolbars) {
        this.toolbars = toolbars;
    }

    public List<Registration> getRmiServices() {
        return rmiServices;
    }

    public void setRmiServices(List<Registration> rmiServices) {
        this.rmiServices = rmiServices;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        if (services != null) {
            for (ServiceContainer container : services) {
                nodesConfig.getServiceConfig().addServices(container.getServiceMappings());
            }
        }

        if (startupExtensions != null)
            nodesConfig.getStartupExtensionConfig().addStartupExtensions(startupExtensions);
        
        if (contentTypeMappers != null)
            nodesConfig.getContentTypeMapperConfig().addContentTypeMappers(contentTypeMappers);
        
        if (navigations != null)
            nodesConfig.getNavigationConfig().addNavigations(navigations);
        
        if (appletJars != null)
            nodesConfig.getAppletJarConfig().addJarConfigs(appletJars); 
        
        if (clientConfigFile != null)
            nodesConfig.getClientConfig().addClientConfigFile(clientConfigFile);
        
        if (toolbars != null) {
            for (ToolbarRenderer toolbar : toolbars)
                nodesConfig.getToolbarConfig().addToolbar(toolbar.getContentType(), toolbar);
        }
        
        if (rmiServices != null) {
            for (Registration rmiService : rmiServices)
                nodesConfig.addRmiService(rmiService);
        }
    }
}
